package clubhouse.control;

import java.util.ListIterator;
import java.util.Vector;

public class ErrorRetriever {

	private Vector<double[]> error;
	private Vector<double[]> errorpool;
	
	
	public ErrorRetriever() {
		error = new Vector<double[]>(100, 10);
		errorpool = new Vector<double[]>(100, 100);
	}
	
	public void storeError(double step, int id, double errX, double errY) {
		error.add(new double [] {step, id, errX, errY});
	}
	
	public double[] getError(double step, int id) {
		double[] temp = null, result = null;
        ListIterator<double[]> li = this.error.listIterator();
        while(li.hasNext()){
        	temp = li.next();
        	if ((temp[0] == step) && (temp[1] == id)) {
        		result = temp;
        		break;
        	}
        }
		return result;
	}
	
	public void genrateErrorPool() {
		int i;
		int step = 0;
		for(i = 0; i<2000; i++) {
			double err = (Math.random()*2-1);
			errorpool.add(new double [] {step, err});
			step++;
		}
	}
	
	public double[] getErrorFromPool(int step) {
		double[] temp = null, result = null;
        ListIterator<double[]> li = this.errorpool.listIterator();
        while(li.hasNext()){
        	temp = li.next();
        	if (temp[0] == step) {
        		result = temp;
        		break;
        	}
        }
		return result;
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
